#!/bin/bash
#SBATCH --job-name=MSE6701
#SBATCH --partition=64c512g
#SBATCH -N 1
#SBATCH --ntasks-per-node=1
#SBATCH --output=%j.out
#SBATCH --error=%j.err

. ../../0-tools/environment

module load intel-oneapi-compilers/2021.4.0
module load intel-oneapi-mpi/2021.4.0
module load intel-oneapi-mkl/2021.4.0

ulimit -s unlimited

# Define the output file and its header
outfile='eng_ecut.dat'
echo '# encut(eV) energy(eV/cell) time-used(seconds)' > ${outfile}

# Loop over e-cut
for ecut in `seq 200 10 400`
do
# Prepare INCAR
cat > INCAR << EOF
ISTART = 0
ICHARG = 2
PREC   = Accurate
EDIFF  = 1E-6 
ALGO   = Fast
ENCUT  = ${ecut} # cutoff energy
ISMEAR = -5
LWAVE  = .FALSE.
LCHARG = .FALSE. 
EOF

# Run vasp
mpirun ${VASP}

# Collect necessary info
eng=`grep 'free  energy' OUTCAR | awk '{print $5}'`
sec=`grep 'Total CPU time used' OUTCAR |awk '{print $6}'`
echo "$ecut $eng $sec" >> ${outfile}

rm -rf WAVECAR

done

# Cleanup
rm -rf CHG CHGCAR CONTCAR DOSCAR EIGENVAL IBZKPT OSZICAR OUTCAR PBS.batch PCDAT vasprun.xml XDATCAR REPORT
